#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using i128 = __int128;
const int N = 1e6 + 5;

void solve() {
    int n;
    cin >> n;
    int mid = n / 2;
    vector<int> a(n);
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    ll mid1, mid2;
    if (mid % 2 != 0) {
        mid1 = a[mid / 2];
        mid2 = a[mid / 2 + mid];
    } else {
        mid1 = (a[mid / 2] + a[mid / 2 - 1]) / 2;
        mid2 = (a[mid + mid / 2 - 1] + a[mid + mid / 2]) / 2;
    }
    if (mid1 == mid2) {
        ll sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;
        for (int i = 0; i < mid; i++) {
            sum1 += abs(mid1 + 1 - a[i]);
        }
        for (int i = mid; i < n; i++) {
            sum1 += abs(mid2 - a[i]);
        }
        for (int i = 0; i < mid; i++) {
            sum2 += abs(mid1 - a[i]);
        }
        for (int i = mid; i < n; i++) {
            sum2 += abs(mid2 + 1 - a[i]);
        }
        for (int i = 0; i < mid; i++) {
            sum3 += abs(mid1 - 1 - a[i]);
        }
        for (int i = mid; i < n; i++) {
            sum3 += abs(mid2 - a[i]);
        }
        for (int i = 0; i < mid; i++) {
            sum4 += abs(mid1 - a[i]);
        }
        for (int i = mid; i < n; i++) {
            sum4 += abs(mid2 - 1 - a[i]);
        }
        ans += min(min(sum1, sum2), min(sum3, sum4));
    } else {
        for (int i = 0; i < mid; i++) {
            ans += abs(mid1 - a[i]);
        }
        for (int i = mid; i < n; i++) {
            ans += abs(mid2 - a[i]);
        }
    }
    cout << ans << endl;

    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t;
    cin >> t;
    while (t--) solve();

    return 0;
}